package j07arraylist;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

public class J1 {
    public static void main(String[] args) {
        ArrayList<String> arr1 = new ArrayList<>();
        arr1.add("a");
        arr1.add("a");
        arr1.add("x");
        arr1.add("b");
        // for each
//        for (String temp:arr1) {
//            System.out.println("temp = " + temp);
//        }

        System.out.println("====");
        Iterator<String> it = arr1.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
//        System.out.println("it.hasNext() = " + it.hasNext());
//        System.out.println("it.next() = " + it.next());
//        System.out.println("it.hasNext() = " + it.hasNext());
//        System.out.println("it.next() = " + it.next());
//        System.out.println("it.hasNext() = " + it.hasNext());
//        System.out.println("it.next() = " + it.next());
//        System.out.println("it.hasNext() = " + it.hasNext());
//        System.out.println("it.next() = " + it.next());
//        System.out.println("it.hasNext() = " + it.hasNext());
//        System.out.println("it.next() = " + it.next());
//        System.out.println("it.hasNext() = " + it.hasNext());
//        System.out.println("it.next() = " + it.next());
//        System.out.println("it.hasNext() = " + it.hasNext());
//        System.out.println("it.next() = " + it.next());
//        System.out.println("it.hasNext() = " + it.hasNext());
//        System.out.println("it.next() = " + it.next());
    }
}

class J2{
    //数据删除
    public static void main(String[] args) {
//        ArrayList<String> arr = new ArrayList<>();
//        List<String> l1 = new ArrayList<>();
//        List<String> l1 = Arrays.asList("a","x","s");
        ArrayList<String> l1 = new ArrayList<>();
        l1.add("a");
        l1.add("x");
        l1.add("s");

        System.out.println("l1 = " + l1);
        //for循环删除
//        for (int i = 0; i < l1.size(); i++) {
//            if(l1.get(i).equals("x")){
//                l1.remove(i);
//            }
////            System.out.println(l1.get(i));
//        }
//        System.out.println("l1 = " + l1);

        //foreach不能删,有问题，具体问题以后再说
        for (String s:l1) {
            if(s.equals("x")){
                l1.remove(s);
            }
        }
        System.out.println("l1 = " + l1);
    }
}
